package com.org.manhu.chargehelper;

import java.util.HashMap;
import java.util.Map;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.org.manhu.chargehelper.download.DownloadTask;
import com.org.manhu.chargehelper.service.ServerService;
import com.org.manhu.chargehelper.tools.CrashHandler;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.WindowManager;

/**
 * @文件名：ChargeApplication.java
 * @包名：com.org.manhu.chargehelper
 * @作者：李朋辉 @QQ：892839211
 * @创建时间：2015年2月4日 下午1:17:04
 *
 * @描述：
 */
@SuppressLint("SdCardPath")
public class ChargeApplication extends Application {

	public static Context mApplicationContext;
	private static Display disp;

	public static String APP_ROOT = "/mnt/sdcard/manhu/download/";

	public static boolean isBoxConnected = false;

	private static Map<String, String> initInfo = new HashMap<String, String>();
	/** 离线安装列表，map的key值为应用的包名，map的value值为应用的appId **/
	public static Map<String, String> offlineInstallList = new HashMap<String, String>();
	/** 在线安装列表 ，map的key值为应用的包名，map的value值为应用的appId **/
	public static Map<String, String> installList = new HashMap<String, String>();
	private static Map<String, Integer> awardMap = new HashMap<String, Integer>();

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		mApplicationContext = getApplicationContext();

		WindowManager manager = (WindowManager) mApplicationContext
				.getSystemService(Context.WINDOW_SERVICE);
		disp = manager.getDefaultDisplay();

		Intent intent = new Intent(mApplicationContext, ServerService.class);
		startService(intent);

		CrashHandler.getInstance().init(mApplicationContext);

		initImageLoader(mApplicationContext);
	}

	public static int getScreenWidth() {
		return disp.getWidth();
	}

	public static int getScreenHeight() {
		return disp.getHeight();
	}

	public static void setInitInfo(Map<String, String> map) {
		initInfo.putAll(map);
	}
	
	public static void updateInitInfo(Map<String, String> map){
		initInfo.clear();
		initInfo.putAll(map);
	}

	public static Map<String, String> getInitInfo() {
		return initInfo;
	}

	public static void setAwardRecord(String key, Integer value) {
		awardMap.put(key, value);
	}

	public static Integer getAwardRecord(String key) {
		return awardMap.get(key);
	}

	/** 初始化图片加载类配置信息 **/
	public static void initImageLoader(Context context) {
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				context).threadPriority(Thread.MAX_PRIORITY - 5)// 加载图片的线程数
				.denyCacheImageMultipleSizesInMemory() // 解码图像的大尺寸将在内存中缓存先前解码图像的小尺寸。
				.discCacheFileNameGenerator(new Md5FileNameGenerator())// 设置磁盘缓存文件名称
				.tasksProcessingOrder(QueueProcessingType.LIFO)// 设置加载显示图片队列进程
				.writeDebugLogs() // Remove for release app
				.build();

		ImageLoader.getInstance().init(config);

	}

}
